package com.tech.thread.juc.locks;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description:
 * @Author: zl
 * @Date: 2019/7/25 16:00
 */
public class ReentrantLockTest {

    int a = 0;
    ReentrantLock lock = new ReentrantLock();

    public void writer() {
        lock.lock(); // 获取锁
        try {
            a++;
        } finally {
            lock.unlock(); // 释放锁
        }
    }

    public void reader() {
        lock.lock(); // 获取锁
        try {
            int i = a;
//……
        } finally {
            lock.unlock(); // 释放锁
        }
    }

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

    }
}
